﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AddRoomSettingItem : MonoBehaviour
{
    public InputField RoomName;
    public Button AddRoomBtn;
    /// <summary>
    /// 要生成的房间预制体
    /// </summary>
    public GameObject RoomPrefab;
    /// <summary>
    /// 要生成房间的父对象位置
    /// </summary>
    public Transform RoomParent;
    private void Awake()
    {
        AddRoomBtn.onClick.AddListener(()=> { AddRoom(RoomName.text); });
    }
    public void AddRoom(string roomName)
    {
        if(!string.IsNullOrEmpty(roomName))
        {
            GameObject go = Instantiate(RoomPrefab);
            go.transform.SetParent(RoomParent);
            go.GetComponent<Room>().ChangeName(roomName);
            Singleton<RoomManager>.GetInstance().Add(go.GetComponent<Room>());
            // 有新房间添加的时候，向所有在线成员发送房间列表
            if (Singleton<TcpServer>.GetInstance().CurrentState == ServerState.WaitRcving)
                CtlMsgHandle.GetRoomList();
        }
    }
}
